<?php
class ArticleController extends QSource_System_Controller_Action{
	public function init(){
		$this->loadTemplate('default');
	}
	public function indexAction(){ 
		$this->_redirect('/');
	}
	public function detailAction(){
		$alias = $this->_request->getParam('alias','');
		if($alias=='')
		    $this->_redirect('/');
		$model = new Model_Article_Article();
		$item = $model->getItemAlias($alias);
		$modelSite = new Model_SiteInfo_SiteInfo();
		$info = $modelSite->getItemId(1);
		$this->view->headMeta()->appendName('keywords', $item['web_keyword']);
		$this->view->headMeta()->appendName('description', $item['web_description']);
		$this->view->headTitle($item['name'].' - '.$info['name'],true);
		$this->view->data = $item;
		$hit = $item['hit'] + 1;
		$model->update(array('hit'=>$hit), 'id = '.$item['id']);
	}
	public function searchAction(){
		if($this->_request->isPost())
		{
			$key = $this->_request->getParam('txtKeyword','');
			if(trim($key) == "")
				$this->_redirect('/');
			if(trim($key) == "Tìm kiếm")
				$this->_redirect('/');
			$modelArticle = new Model_Article_Article();
			$data = $modelArticle->getAllStartWith($key);
			$this->view->count = count($data);
			Zend_View_Helper_PaginationControl::setDefaultViewPartial(APPLICATION_PATH.'\modules\default\views\pagination.phtml');
			$pa = Zend_Paginator::factory($data);
			$pa->setItemCountPerPage(20);
			$current = $this->_request->getParam('page');
			$this->view->page = $current;
			$pa->setCurrentPageNumber($current);
			$this->view->data = $pa;
			$modelSite = new Model_SiteInfo_SiteInfo();
			$info = $modelSite->getItemId(1);
			$this->view->key = $key;
			//$this->view->headMeta()->appendName('keywords', $item['web_keyword']);
			//$this->view->headMeta()->appendName('description', $item['web_description']);
			$this->view->headTitle('Tìm kiếm - '.$info['name'],true);
		}
		else
		{
			$this->_redirect('/');
		}
	}
}